<template>
    <div>
        <Dialog :show="dialogConfig.show" :title="dialogConfig.title" :buttons="dialogConfig.buttons" width="500px"
            :showCancel="false" @close="dialogConfig.show = false">
            <el-form :model="formData" label-width="120px" @submit.prevent>
                <!--发布-->
                <el-form-item label="发布人" prop="">
                    <Avatar :userId="formData.userId" :width="40"></Avatar>
                    <span :style="{ 'margin-left': '5px' }">{{ formData.nickName }}</span>
                </el-form-item>
                <!-- 文件名 -->
                <el-form-item label="文件名" prop="">
                    {{ formData.fileName }}
                </el-form-item>
                <!-- 文件大小 -->
                <el-form-item label="大小" prop="">
                    {{ proxy.Utils.sizeToStr(formData.fileSize) }}
                </el-form-item>
                <!-- 所需积分 -->
                <el-form-item label="下载所需积分" prop="">
                    {{ formData.integral }}
                </el-form-item>
                <!-- 下载按钮 -->
                <el-form-item label="" prop="">
                    <a target="_blank" :href="'/api/forum/attachmentDownload?fileId=' + formData.fileId" class="a-link">
                        下载
                    </a>
                </el-form-item>
            </el-form>
        </Dialog>
    </div>
</template>

<script setup>
import { ref, reactive, getCurrentInstance } from "vue";
import { useRouter, useRoute } from "vue-router";
const { proxy } = getCurrentInstance();
const router = useRouter();
const route = useRoute();

const dialogConfig = reactive({
    show: false,
    title: "查看附件",
    buttons: [
        {
            text: "关闭",
            click: (e) => {
                dialogConfig.show = false;
            },
        },
    ],
});

const api = {
    //获取附件信息
    getAttachment: "/forum/getAttchment",
}

const formData = ref({})
const show = async (nickName, articleId) => {
    dialogConfig.show = true;
    let result = await proxy.request({
        url: api.getAttachment,
        params: {
            articleId: articleId,
        }
    })
    if (!result) {
        return;
    }
    formData.value = result.data;
    formData.value.nickName = nickName;
}

//对外暴露的子组件方法
defineExpose({ show });

</script>

<style lang="scss" scoped></style>